package utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by iss on 17/10/17.
 */
public class FileReader4 {

    public static void main(String[] args) throws IOException {

        Set<String> result = new HashSet<>();

        Set<String> allSet = new HashSet<>();

        Set<String> usedSet = new HashSet<>();

        File file = new File("/Users/iss/mobiles-chengdu.txt");
        java.io.FileReader fr = new java.io.FileReader(file);

        BufferedReader br = new BufferedReader(fr);

        String str = br.readLine();

        while (str != null) {
            try {
                if (str.length() == 11) {
                    allSet.add(str);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            str = br.readLine();
        }

        br.close();
        fr.close();

        file = new File("/Users/iss/uuu.txt");
        fr = new java.io.FileReader(file);

        br = new BufferedReader(fr);

        str = br.readLine();

        while (str != null) {
            try {
                str = str.substring(str.indexOf(")") + 2, str.length() - 1);
                if (str.length() == 11) {
                    usedSet.add(str);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            str = br.readLine();
        }

        br.close();
        fr.close();

        result.clear();
        result.addAll(allSet);
        result.removeAll(usedSet);

        System.out.println("total = " + allSet.size());
        System.out.println("used = " + usedSet.size());
        System.out.println("remain = " + result.size());

        int count = 0;
        for (String s : result) {
            count++;

            if (count == 100) {
                count = 0;
                System.out.println();
            }

            System.out.print(s + " ");
        }
    }

}
